{{!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
--}}

<div class="yarn-flow-runinfo">
  <h3>Flow Run Info</h3>
  <div class="panel panel-default">
    <div class="panel-body">
      <table class="table table-striped table-bordered">
        <tbody>
          <tr>
            <td>Flow Name</td>
            <td>{{model.flowrun.flowName}}</td>
          </tr>
          <tr>
            <td>Run ID</td>
            <td>{{model.flowrun.shownid}}</td>
          </tr>
          <tr>
            <td>Launched By</td>
            <td>{{model.flowrun.user}}</td>
          </tr>
          <tr>
            <td>Run Sequence ID</td>
            <td>{{model.flowrun.runid}}</td>
          </tr>
          <tr>
            <td>Start Time</td>
            <td>{{model.flowrun.createTime}}</td>
          </tr>
          <tr>
            <td>End Time</td>
            <td>{{model.flowrun.endTime}}</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>

  {{#if (or cpuVCoresVizData.length memoryVizData.length)}}
  <div class="dropdown pull-right">
    <button class="btn btn-sm btn-primary dropdown-toggle" type="button" data-toggle="dropdown">
      Add Metrics Widget <span class="caret"></span>
    </button>
    <ul class="dropdown-menu">
      {{#if cpuVCoresVizData.length}}
        <li>
          <a href="#" {{action "addVizWidget" "cpuVcores"}}>
            <div class="item-icon">
              {{#if vizWidgets.cpuVcores}}
                <i class="glyphicon glyphicon-ok text-success"></i>
              {{/if}}
            </div>
            <div class="item-text">Application Vs Cpu Vcores</div>
          </a>
        </li>
      {{/if}}
      {{#if memoryVizData.length}}
        <li>
          <a href="#" {{action "addVizWidget" "memoryUsed"}}>
            <div class="item-icon">
              {{#if vizWidgets.memoryUsed}}
                <i class="glyphicon glyphicon-ok text-success"></i>
              {{/if}}
            </div>
            <div class="item-text">Application Vs Memory Used</div>
          </a>
        </li>
      {{/if}}
    </ul>
  </div>
  {{/if}}

  <!-- Flowrun aggregated data -->
  <h3>Applications</h3>
  {{em-table columns=columns rows=model.apps}}

  {{#if (and cpuVCoresVizData.length vizWidgets.cpuVcores)}}
    <div class="panel panel-default">
      <div class="panel-body">
        <div class="glyphicon glyphicon-remove pull-right" {{action "removeVizWidget" "cpuVcores"}}>
        </div>
        <h4 class="text-center">Application Vs CPU VCores</h4>
        {{simple-bar-chart
          class="chart-panel"
          data=cpuVCoresVizData
          xAxisTickFormatter=appIdFormatter
          xAxisText="Application"
          yAxisText="CPU VCores"
          onBarChartClickCallback=onBarChartClick
        }}
      </div>
    </div>
  {{/if}}

  {{#if (and memoryVizData.length vizWidgets.memoryUsed)}}
    <div class="panel panel-default">
      <div class="panel-body">
        <div class="glyphicon glyphicon-remove pull-right" {{action "removeVizWidget" "memoryUsed"}}>
        </div>
        <h4 class="text-center">Application Vs Memory Used</h4>
        {{simple-bar-chart
          class="chart-panel"
          data=memoryVizData
          xAxisTickFormatter=appIdFormatter
          yAxisTickFormatter=memoryFormatter
          xAxisText="Application"
          yAxisText="Memory Used"
          onBarChartClickCallback=onBarChartClick
        }}
      </div>
    </div>
  {{/if}}
</div>
